package com.jastar.android.jigsaw.util;

import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.stream.IntStream;

public class RandomUtil {

    public static final Random random = new Random(System.currentTimeMillis());

    public static <T> T randomListItem(List<T> list) {
        return list.get(random.nextInt(list.size()));
    }

    public static int[] randomNumber(int min, int max, int count) {
        int[] res = new int[count];
        Set<Integer> set = new HashSet<>();
        IntStream.range(0, count).forEach(i -> {
            int num;
            do {
                num = random.nextInt(max - min + 1) + min;
            } while (set.contains(num));
            res[i] = num;
            set.add(num);
        });
        return res;
    }

}
